package com.rayo.accesscontrollercopy.model.db.dao;

import com.litesuits.orm.db.assit.QueryBuilder;
import com.litesuits.orm.db.assit.WhereBuilder;
import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.KeyTimezoneData;

import java.util.List;

/**
 * Created by yanghaojie on 16/7/27.
 */
public class KeyTimeImpl implements KeyTimeDao {

    @Override
    public List<KeyTimezoneData> findAll() {
        return DbHelp.getQueryAll(KeyTimezoneData.class);
    }

    @Override
    public KeyTimezoneData findByNo(int no, int serial) {
        QueryBuilder qb = new QueryBuilder(KeyTimezoneData.class).whereEquals(KeyTimezoneData.TIMEZONE_ID, no)
                .whereAppendAnd().whereEquals(KeyTimezoneData.SERIAL_ID, serial);
        List<KeyTimezoneData> list = DbHelp.liteOrm.query(qb);
        if (null == list || list.isEmpty()) return null;
        else return list.get(0);
    }

    @Override
    public void addAll(List<KeyTimezoneData> data) {
        DbHelp.insertAll(data);
    }

    @Override
    public void addKeyTime(KeyTimezoneData data) {
        DbHelp.insert(data);
    }

    @Override
    public void updateAll(List<KeyTimezoneData> data) {
        DbHelp.updateALL(data);
    }

    @Override
    public void updateKeyTime(KeyTimezoneData data) {
        DbHelp.update(data);
    }

    @Override
    public void deleteAll() {
        DbHelp.deleteAll(KeyTimezoneData.class);
    }

    @Override
    public void deleteKeyTime(KeyTimezoneData data) {
        DbHelp.delete(data);
    }

    @Override
    public void deleteByKeyTimeByNo(int id) {
        WhereBuilder qb = new WhereBuilder(KeyTimezoneData.class)
                .where(KeyTimezoneData.TIMEZONE_ID, new String[]{String.valueOf(id)});
        DbHelp.liteOrm.delete(qb);
    }
}
